/*
 * All rights Reserved, Designed By www.goldbeacon.cn
 * @Title:  demo
 * @Package cn.goldbeacon.demo.common.exception
 * @author: zoujie
 * @date:   2021/8/1114:57
 * @version V1.0
 * Copyright © 2021 www.goldbeacon.cn. All Rights Reserved.
 * 注意：本内容仅限于湖南金烽信息科技有限公司内部传阅，禁止外泄以及用于其他的商业目
 */
package com.chenzhengrong.demospringboot.handler;

import com.chenzhengrong.demospringboot.enums.HttpStatusEnum;
import lombok.Getter;

import java.io.Serializable;

/**
 * @author zoujie
 * @title: CustomBusinessException
 * @description: 自定义业务异常，一般用于将一些系统错误包装为业务异常往上层抛出
 * @date 2021/8/1114:57
 */
@Getter
public class BusinessException extends RuntimeException implements Serializable {

    /** 序列化版本号 */
    private static final long serialVersionUID = -714077885272075627L;

    /** 异常消息 */
    private String msg;

    /** 异常代码 */
    private int code = 500;

    public BusinessException(String msg) {
        super(msg);
        this.msg = msg;
    }

    public BusinessException(HttpStatusEnum httpStatusEnum) {
        super(httpStatusEnum.getMsg());
        this.msg = httpStatusEnum.getMsg();
        this.code = httpStatusEnum.getCode();
    }

    public String getMsg() {
        return msg;
    }

    public int getCode() {
        return code;
    }
}
